

<?php
include_once "include/constants.php" ;
    function getMovieData($movieid) {
        $genreId = array("Action" => 0,
					"Adult" => 1,
					"Adventure" => 2,
					"Animation" => 3,
					"Biography" => 4,
					"Comedy" => 5,
					"Crime" => 6,
					"Documentary" => 7,
					"Drama" => 8,
					"Family" => 9,
					"Fantasy" => 10,
					"Film-Noir" => 11,
					"History" => 12,
					"Horror" => 13,
					"Music" => 14,
					"Musical" => 15,
					"Mystery" => 16,
					"Romance" => 17,
					"Sci-Fi" => 18,
					"Short" => 19,
					"Sport" => 20,
					"Thriller" => 21,
					"War" => 22,
					"Western" => 23);
        //Genre: 0, Director: 1, Writer: 2, Actor: 3
        $movieData = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
        try {
            $conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			
            //get genres data
            $stmt = $conn->prepare("select * from genres where movieid=$movieid");
            $stmt->execute();
            
            while ($data_row = $stmt->fetch()) {
                $movieData[0][] = $genreId[$data_row['genre']];
            }
			
			//get director data
			$stmt = $conn->prepare("select * from movies2directors where movieid=$movieid");
            $stmt->execute();
            
            while ($data_row = $stmt->fetch()) {
                $movieData[1][] = $data_row['directorid'];
            }
			
			//get write data
			$stmt = $conn->prepare("select * from movies2writers where movieid=$movieid");
            $stmt->execute();
            
            while ($data_row = $stmt->fetch()) {
                $movieData[2][] = $data_row['writerid'];
            }
			
			//get actor data
			$stmt = $conn->prepare("select * from movies2actors where movieid=$movieid and char_num > 0 order by char_num desc ");
            $stmt->execute();
            
            while ($data_row = $stmt->fetch()) {
                $movieData[3][] = $data_row['actorid'];
            }
			
        } catch(PDOException $e) {
            echo 'ERROR: ' . $e->getMessage();
        }
		
		
        //print_r($movieData);
        return $movieData;
    }
    getMovieData(1353247);
?>
